/**
 * 在这里combine reducer
 */
import { combineReducers } from 'redux';
import login from 'reducers/login';
import cache from 'reducers/cache';
import main from 'reducers/main';
import budget from 'reducers/budget';
import setting from 'reducers/setting';
import billing from 'reducers/billing';
import creditSetting from 'reducers/credit-setting';
import permissionData from 'reducers/permission-data';
import financialAccount from 'reducers/financial-account';

/**
 * redux过时了，为了兼容写个reducer，以后全面改用Context API
 */
function expenseCache(state = {}, action) {
  if (action.type === 'SET_EXPENSE_CACHE') {
    return {...state, [action.payload.expenseTypeOID]: action.payload};
  }

  return state;
}

const reducers = {
  login,
  cache,
  expenseCache,
  main,
  budget,
  setting,
  billing,
  creditSetting,
  permissionData,
  financialAccount
};
const combined = combineReducers(reducers);
module.exports = combined;
